package com.third.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.third.entity.Brand;
import com.third.entity.OutboundOrder;
import com.third.entity.PageInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Mapper
public interface Outbound_mapper extends BaseMapper<OutboundOrder> { //对出库单进行操作

    /*@Select("select *,b.brand_id b_id from outbound_order o,brand b,user u where o.customer_id=u.user_id and o.brand_id=b.brand_id "+
            "and brand_name like +'%'||#{brandName}||'%'")*/
    @Select("<script>"+
                "select *,b.brand_id "+
                "from outbound_order o,brand b,user u"+
                "<where>"+
                "o.customer_id=u.user_id and o.brand_id=b.brand_id "+
                "<if test='brandName !=null and brandName!=\"\"'>"+
                "and b.brand_name like CONCAT('%', #{brandName}, '%') "+
                "</if>"+
                "<if test= 'userName !=null and userName!=\"\"'>"+
                "and u.username like CONCAT('%', #{userName}, '%') "+
                "</if>"+
                "<if test= 'orderId !=null and orderId!=\"\"'>"+
                "and o.order_id like CONCAT('%', #{orderId}, '%')  "+
                "</if>"+
                "</where>"+
                " ORDER BY o.order_id "+
                "limit #{start},#{size}"+
                "</script>")
    @Results({
            @Result(property = "orderId",column = "order_id"),
            @Result(property = "orderDate",column = "order_date"),
            @Result(property = "orderType",column = "order_type"),
            @Result(property = "user.userId",column = "user_id"),
            @Result(property = "user.username",column = "username"),
            @Result(property = "brand.brandName",column = "brand_name"),
            @Result(property = "brand.brandId",column = "brand_id"),
            @Result(property = "brand.specification",column = "specification"),
            @Result(property = "permission",column = "permission")
    })
    List<OutboundOrder> getList(HashMap<String,Object> map);

}
